//
//  LaunchPOPView.swift
//  你的AI
//
//  Created by 丸子 on 2024/6/3.
//

import UIKit

class LaunchPOPView: UIView {

    lazy var backView: UIView = {
       let view = UIView()
        view.backgroundColor = UIColor.white
        view.allRound(8)
        return view
    }()
    
    lazy var titleLb: UILabel = {
       let label = UILabel()
        label.textColor = Theme.color.text_d1
        label.font = UIFont.pingFangSCRegular(ofSize: 16)
        label.text = "个人信息保护指引"
        return label
    }()
    
    lazy var descLb: UILabel = {
       let label = UILabel()
        label.textColor = Theme.color.text_d3
        label.font = UIFont.pingFangSCRegular(ofSize: 14)
        label.numberOfLines = 0
        label.text = "我们将通过用户协议和隐私政策，帮助您了解我们为您提供的服务、我们如何处理个人信息以及您享有的权利。 点击“同意”按钮，表示您已知情并同意以上协议和以下约定。\n\n 1.请你知悉，您同意隐私政策仅代表您已了解应用提供的功能，以及功能运行所必需的个人信息，并不代表您已同意我们可以收集非必要个人信息，非必要个人信息会根据您使用过程中的授权情况单独征求您的同意。 \n\n2.我们尊重您的选择权，您可以访问、修改、删除您的个人信息您的授权，我们也为您提供注销、投诉渠道。"
        return label
    }()
    
    lazy var noBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(Theme.color.text_d1, for: .normal)
        button.titleLabel?.font = UIFont.pingFangSCRegular(ofSize: 16)
        button.allRound(22)
        button.layer.borderWidth = 1
        button.layer.borderColor = Theme.color.text_d2.cgColor
        button.setTitle("不同意", for: .normal)
        return button
    }()
    
    lazy var yesBtn: UIButton = {
        let button = UIButton(type: .custom)
        button.setTitleColor(.white, for: .normal)
        button.titleLabel?.font = UIFont.pingFangSCRegular(ofSize: 16)
        button.allRound(22)
        button.backgroundColor = Theme.color.main
        button.setTitle("同意并继续", for: .normal)
        return button
    }()
    
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT))
        backgroundColor = UIColor(hexString: "#000000", transparency: 0.3)
        addSubviews([backView])
        backView.addSubviews([titleLb, descLb, noBtn, yesBtn])
        backView.snp.makeConstraints { make in
            make.centerX.centerY.equalToSuperview()
            make.leading.trailing.equalToSuperview().inset(24)
            make.top.equalTo(titleLb.snp.top).offset(-22)
            make.bottom.equalTo(noBtn.snp.bottom).offset(28)
        }
        
        titleLb.snp.makeConstraints { make in
            make.top.equalTo(22)
            make.centerX.equalToSuperview()
        }
        
        descLb.snp.makeConstraints { make in
            make.top.equalTo(titleLb.snp.bottom).offset(16)
            make.leading.trailing.equalToSuperview().inset(28)
        }
        
        noBtn.snp.makeConstraints { make in
            make.top.equalTo(descLb.snp.bottom).offset(16)
            make.leading.equalTo(20)
            make.height.equalTo(44)
            make.width.equalTo(yesBtn.snp.width)
        }
        
        yesBtn.snp.makeConstraints { make in
            make.top.equalTo(descLb.snp.bottom).offset(16)
            make.trailing.equalTo(-20)
            make.height.equalTo(44)
            make.leading.equalTo(noBtn.snp.trailing).offset(16)
        }
        
        backView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
        UIView.animate(withDuration: 0.3, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: { [weak self] in
            self?.backView.transform = .identity
        }, completion: nil)
     
        
        noBtn.setClosureTouchUpInside_k {
            exit(0)
        }
        
        yesBtn.setClosureTouchUpInside_k {
            self.removeFromSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
